/* 
 * File:   raytracer.h
 * Author: chaterolas
 *
 * Created on 24 de junio de 2009, 10:42 PM
 */

#ifndef _RAYTRACER_H
#define	_RAYTRACER_H

#include "scene.h"
#include "../primitives/light.h"
#include "../primitives/pointlight.h"
#include "../primitives/arealight.h"
#include "../base/matriz.h"
#include <omp.h>
#include <pngwriter.h>

#define DIST_LIMT   100000.0
#define TRACE_DEPTH 1
#define F_DIST  5.0

class RayTracer {
public:
    RayTracer(Scene *s, int depth);
    virtual ~RayTracer();

    void render();    

private:
    Scene *scene;
    int w, h, s, depth;    
    double d, pL, pT;
    Color **fb;
    Vector3D *ulb, *urb, *blb, *brb;
    Vector3D *ax, *ay;


    Primitive *nearest(Ray *r);
    Vector3D *getLightDir(Vector3D *inter, Light *l);
    Color *getLightSpecular(Vector3D *ldir, Vector3D *inter, Ray *r, Primitive *p);
    double calcShade(Light *l, Vector3D *ldir, Vector3D *inter);
    Primitive *getshadowInt(Ray *r, Light *l);
    Color *getReflectColor(Primitive *p, Vector3D *ip, Ray *r, int depth);
    Color *getRefractionColor(Primitive *p, Vector3D *ip, Ray *r, int depth);

    void setCameraPosition();
    void outputImage();
    void rayTrace(Ray *r, Color *c, int depth);

    int p(int x, int y);
    double randomNumber();
};

#endif	/* _RAYTRACER_H */

